﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using Luna小店.UC.辅料;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna小店.UC.款式类别
{
    public partial class Frm款式类别预览 : DevExpress.XtraEditors.XtraForm
    {
        public String materialCatelogId;
        public String STYLE_CATEGORY;
        public List<DTO辅料大分类> dto辅料大分类 = new List<DTO辅料大分类>();
        public List<DTO辅料位置> dto辅料位置 = new List<DTO辅料位置>();
        public Frm款式类别预览(String STYLE_CATEGORY)
        {
            this.STYLE_CATEGORY = STYLE_CATEGORY;
            InitializeComponent();
            this.dto辅料大分类 = FunctionHelper.JsonDeserialization<List<DTO辅料大分类>>(RestCall.httpGetMethod(URL.接口url+"/acc/generateQCItem?styleCategory=" + this.STYLE_CATEGORY));
            this.gridControl辅料类别.DataSource = this.dto辅料大分类;
            this.gridControl辅料位置.DataSource = this.dto辅料位置;
        }

        private void gridView辅料类别_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            this.materialCatelogId = FunctionHelper.GetgridViewValue(this.gridView辅料类别, e.RowHandle, "id");
            if (this.dto辅料位置 == null)
            {
                this.dto辅料位置 = new List<DTO辅料位置>();
            }
            this.dto辅料位置.Clear();
            this.dto辅料位置 = FunctionHelper.JsonDeserialization<List<DTO辅料位置>>(RestCall.httpGetMethod(URL.接口url+"/acc/getAccessoryPartDTO?category=" + this.STYLE_CATEGORY + "&accessoryItemID=" + FunctionHelper.GetgridViewValue(this.gridView辅料类别, e.RowHandle, "id")));
            this.gridControl辅料位置.DataSource = dto辅料位置;
        }

        private void 新增辅料类别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Frm款式类别下新增辅料类别(this.dto辅料大分类).ShowDialog();
            this.gridView辅料类别.RefreshData();
        }

        private void 新增位置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.dto辅料位置 == null)
            {
                this.dto辅料位置 = new List<DTO辅料位置>();
            }
            new Frm款式类别下增加辅料位置(this.dto辅料位置, this.materialCatelogId, this.STYLE_CATEGORY).ShowDialog();
            
            this.gridView辅料位置.RefreshData();
        }
    }
}
